package com.bankcomm.ui.specialwidget;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.bankcomm.R;
import com.bankcomm.bean.GroupCity;
import com.bankcomm.bean.ItemCity;
import com.bankcomm.util.LPUtils;
import com.rytong.tools.datastorage.PackageManagerAndroid;
import com.rytong.tools.ui.BaseView;
import com.rytong.tools.ui.Component;
import com.rytong.tools.ui.CssStyle;
import com.rytong.tools.utils.Utils;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

/**
 * 城市选择控件
 * 
 * @author zhang.h
 * 
 * @date 2012-5-25 上午10:58:44
 */
public class LPCityChooser extends Component {
	private static final String SAVECITY = "saveCity";
	private Dialog dialog;

	/** 自动提示 */
	CityAutoCompleteText cityAutoText = null;
	
	/** 城市选择界面外层布局 */
	private LinearLayout outerLL;
	
	/** 滚动布局 */
	private ScrollView sv;

	/** 城市选择界面内层布局 */
	private LinearLayout interLL;

	/** 每行布局 */
	private LinearLayout rowLL = null;

	/** 布局参数 */
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);

	/** 分组城市集合 */
	private List<GroupCity> groupCities = null;

	/** 默认显示列数 */
	private int col;

	// 单个城市控件的宽高(高度默认为20)
	private int CITY_RB_WIDTH = 0;
	private int CITY_RB_HEIGHT = 0;

	// 所有RB城市集合
	private List<CityRadioButton> rbs = new ArrayList<CityRadioButton>();

	// 是否显示搜索框
	private boolean isShowSearch = true;

	private int SV_PADDING_TOP = Utils.getScaledValueY(0);
	private int SV_PADDING_BOTTOM = Utils.getScaledValueY(16);
	private int AUTO_TEXT_HEIGHT =  Utils.getScaledValueY(30);

	/** activity */
	private BaseView bv_ = null;
	
	// 提交的城市Value
	private String cityValue;
	// 是否保存提交城市
	private String saveCity; 

	private Bitmap checkBitmap = null;
	public String getCityValue() {
		return cityValue;
	}

	public void setCityValue(String cityValue) {
		this.setPropertyByName("value", cityValue);
		if (realView_ != null) {
			MyLPCityChooser mlpcc = (MyLPCityChooser)realView_;
			setCityStyle(mlpcc, getCityName(cityValue));
		}
		this.cityValue = cityValue;
	}
	
	@Override
	public void initRealView(Activity activity, String nodeValue) {
		realView_ = new MyLPCityChooser(activity);
		MyLPCityChooser mlpcc = (MyLPCityChooser)realView_;
		setCityStyle(mlpcc, getCityName(cityValue));
	}

	public class MyLPCityChooser extends TextView implements CompositedComponent {

		public MyLPCityChooser(Context context) {
			super(context);
			bv_ = (BaseView) context;
			dialog = new Dialog(context,R.style.alertdialog);
			
			setGravity(Gravity.CENTER);

			// 初始化城市PopWindow数据(宽、高、显示列数等)
			initCityPW();

			// 初始化默认值
			initDefaultValue();

			// 初始化分组城市数据
			initCityDatas(null);

			// 生成城市控件
			generateCityView(context);
		}

		private void initCityPW() {
			col = getPropertyByName("col") != null ? Integer.valueOf(getPropertyByName("cityCol").toString()) : 3;
			CITY_RB_WIDTH = (int) (LPUtils.screenwidth*1.0f / col*1.0f);
			
			if(null == checkBitmap || checkBitmap.isRecycled()){
				checkBitmap = ((BitmapDrawable) getResources().getDrawable(R.drawable.checkcity)).getBitmap();				
			}
			
			CITY_RB_HEIGHT = Math.max(checkBitmap.getHeight(),Utils.getScaledValueX(25));
		}
		
		private void initDefaultValue() {
			Object defaultValueObj = getPropertyByName("defaultValue");
			saveCity = getPropertyByName("saveCity");
			String defaultSaveCity = PackageManagerAndroid.ANDROIDDB.get(SAVECITY);
			
			if (saveCity != null && saveCity.equals("true") && !defaultSaveCity.equals("")) {
				int num = defaultSaveCity.indexOf("|");
				// 给文本框赋值
				this.setText(defaultSaveCity.substring(0, num));

				// 设置提交值
				setCityValue(defaultSaveCity.substring(0,
						defaultSaveCity.length()));
			} else {
				if (!defaultValueObj.equals("")) {
					String defaultValueStr = String.valueOf(defaultValueObj);
					String allValue = getPropertyByName("allValue");
					if (allValue.equals("true")) {
						int num = defaultValueStr.indexOf("|");
						// 给文本框赋值
						this.setText(defaultValueStr.substring(0, num));

						// 设置提交值
						setCityValue(defaultValueStr.substring(0,
								defaultValueStr.length()));
					} else {
						String[] defaultValueArr = defaultValueStr.split("\\|");

						// 给文本框赋值
						this.setText(defaultValueArr[defaultValueArr.length - 2]);

						// 设置提交值
						setCityValue(defaultValueArr[defaultValueArr.length - 1]);
					}
				}
			}
		}

		private void generateCityView(Context context) {
			// 外层布局
			outerLL = new LinearLayout(context);
			outerLL.setOrientation(LinearLayout.VERTICAL);
			outerLL.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
			outerLL.setGravity(Gravity.CENTER_HORIZONTAL);
			outerLL.setBackgroundColor(Color.WHITE);
			// 设置自动提示文本不自动获取焦点
			outerLL.setFocusable(true);
			outerLL.setFocusableInTouchMode(true);

			// 垂直滚动条
			sv = new ScrollView(context);
			sv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1));
			sv.setPadding(0, SV_PADDING_TOP, 0, SV_PADDING_BOTTOM);
			sv.setVerticalScrollBarEnabled(true);
			
			// 内层布局
			interLL = new LinearLayout(context);
			interLL.setOrientation(LinearLayout.VERTICAL);
			
			interLL.removeAllViews();
			sv.removeAllViews();
			outerLL.removeAllViews();
			
			// 添加自动提示文本
			if (isShowSearch) {
				cityAutoText = new CityAutoCompleteText(context);
				outerLL.addView(cityAutoText);
			}
			
			addRBView(context, rowLL, groupCities, lp);
			sv.addView(interLL);
			outerLL.addView(sv);
			
			dialog.setContentView(outerLL);
			Window mWindow = dialog.getWindow();
			mWindow.setWindowAnimations(R.style.popupAnimation);
			mWindow.setLayout(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT);
		}

		@Override
		public boolean onTouchEvent(MotionEvent event) {
			dialog.show();
			switch (event.getAction()) {
			case MotionEvent.ACTION_DOWN:
				dialog.show();
				break;
			}
			return super.onTouchEvent(event);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			//adjustXY();
			super.onDraw(canvas);
		}

		@Override
		public Component composited() {
			return LPCityChooser.this;
		}

	}

    /**
     * 该方法主要用于指定控件的大小\显示颜色\样式
     * @return
     * @throws Exception
     *             TODO
     */
	@Override
	public void mouldH() throws Exception {
		// TODO Auto-generated method stub
		super.mouldH();
		if(null == realView_){
			return;
		}
		
		MyLPCityChooser mlpcc = (MyLPCityChooser)realView_;
        // 表示是否有边框，1表示有边框，0表示无边框，无边框的同时也无背景色(0/1)，什么都不写也表示有边框。
        String border = (String) getPropertyByName("border");
        if("".equals(border)){ // 什么都不写，默认有边框。
            final BitmapDrawable bitdraw = new BitmapDrawable(makeBack("" , true));
            setBackgroundDrawable(bitdraw);
        }
        String align = getPropertyByName("align");
        if (null != cssStyle_) {
            if (null != cssStyle().content_
                    && cssStyle().content_.indexOf(CssStyle.BGIMAGEURL) < cssStyle().content_
                            .indexOf(CssStyle.BACKGROUNDCOLOR)) {
                String temp = (String) cssStyle_.getProperty(CssStyle.BACKGROUNDCOLOR);
                if (null != temp && !temp.equals("")) {
                	if("1".equals(border)){//有边框时 画背景色
                		final BitmapDrawable bitdraw = new BitmapDrawable(makeBack(temp , true));
                		setBackgroundDrawable(bitdraw);
                		realView_.setDrawingCacheBackgroundColor(Color.parseColor(temp));
                    } else if("0".equals(border)){//border为0，不画边框。
                    	final BitmapDrawable bitdraw = new BitmapDrawable(makeBack(temp , false));
                	    setBackgroundDrawable(bitdraw);
                        realView_.setDrawingCacheBackgroundColor(Color.parseColor(temp));
                	}
                }

            } else if (null != cssStyle().content_
                    && cssStyle().content_.indexOf(CssStyle.BGIMAGEURL) > cssStyle().content_
                            .indexOf(CssStyle.BACKGROUNDCOLOR)) {
            	setBackgroundDrawableByCssStyle();            
            }
            String alignTemp = cssStyle_.getProperty(CssStyle.TEXTALIGN);
            if (null != alignTemp && !alignTemp.equals(""))
                align = alignTemp;
        }
        if (align.equalsIgnoreCase("right")) {
            setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        } else if (align.equalsIgnoreCase("center")) {
            setGravity(Gravity.CENTER);
        }
        // 设置输入框的提示语言
        mlpcc.setHint((CharSequence) getPropertyByName("hold"));
	}

	/**
     * border = 1 时画背景
     * border = 0 或 "" 时，画边框(黑色边框，白色背景)
     */
    private Bitmap makeBack(String bgColor , boolean isOnlyBorder) {
        Bitmap result = null;
        // 定义圆角
        float[] radii = new float[8];
        for (int i = 0; i < 8; i++) {
            radii[i] = 5;
        }
        // 建立一个和控件同样大小的bitmap。
        result = Bitmap.createBitmap(width_, height_, Bitmap.Config.ARGB_8888);
        // 建立一张画布。
        Canvas canvas = new Canvas(result); // 并且以后绘制都在这张画布上进行。
        // 设置画笔。
        Paint paint = new Paint();
        paint.setAntiAlias(true); // 画笔抗锯齿。
        // 定义一个画图的路径。
        Path path = new Path();
        
        if(!isOnlyBorder){
            paint.setColor(Color.parseColor(bgColor));
        } else {
            paint.setColor(Color.WHITE);
            path.addRoundRect(new RectF(1, 1, width_ - 1, height_ - 2), radii,
                    Path.Direction.CW); // 设置绘制路径。
            canvas.drawPath(path, paint);
            
//            paint.setColor(Color.BLACK);
            paint.setColor(Color.rgb(120, 150, 214));
            paint.setStyle(Paint.Style.STROKE); // 设置空心。
            paint.setStrokeWidth(0.5f); // 设置画笔粗细。
        }
        path.addRoundRect(new RectF(1, 1, width_ - 1, height_ - 2), radii,
                Path.Direction.CW); // 设置绘制路径。
        canvas.drawPath(path, paint); // 绘制边框。
        return result;
    }
    
	/**
	 * 自动提示文本控件
	 */
	class CityAutoCompleteText extends LinearLayout {

		private MyAutoCompleteText autoCompleteText;
		private Context context_;

		public CityAutoCompleteText(Context context) {
			super(context);
			context_ = context;
			autoCompleteText = new MyAutoCompleteText(context);
			autoCompleteText.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,AUTO_TEXT_HEIGHT));
			
			this.setPadding(Utils.getScaledValueX(10), Utils.getScaledValueY(5), Utils.getScaledValueX(10), Utils.getScaledValueY(5));
			this.setBackgroundResource(R.drawable.shop_search_bg);
			this.setGravity(Gravity.CENTER_HORIZONTAL);
			this.setLayoutParams(lp);
			this.addView(autoCompleteText);
		}

		class MyAutoCompleteText extends EditText {

			public MyAutoCompleteText(Context context) {
				super(context);
				//this.setTextSize(Utils.getFontSize(10));
				this.setHint(bv_.getString(R.string.firstletter));
				this.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_btn_search,0,0,0);
				this.setBackgroundResource(R.drawable.input_search_bg);
				this.addTextChangedListener(new TextWatcher() {
					@Override
					public void afterTextChanged(Editable s) {
						// 移除所有View
						interLL.removeAllViews();

						String autoText = s.toString();
						if (autoText != null && autoText.length() > 0) {
							// 搜索字母全部转换为小写
							initCityDatas(autoText.toLowerCase());
						} else {
							initCityDatas(null);
						}
						addRBView(context_, rowLL, groupCities, lp);
					}

					@Override
					public void onTextChanged(CharSequence s, int start, int before, int count) {

					}

					@Override
					public void beforeTextChanged(CharSequence s, int start, int count, int after) {

					}

				});
			}

			@Override
			protected void onDraw(Canvas canvas) {
				//setBackgroundResource(R.drawable.edittext_round_shape);
				super.onDraw(canvas);
			}
		}
	}

	/**
	 * 单个城市控件
	 */
	class CityRadioButton extends RadioButton implements CompositedComponent{

		public ItemCity currIC;

		public CityRadioButton(Context context, ItemCity itemCity) {
			super(context);
			currIC = itemCity;
			setText(currIC.getName());
			this.setGravity(Gravity.CENTER);
			this.setTextColor(Color.BLACK);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			// TODO Auto-generated method stub
			final Paint paint = getPaint();
			paint.setAntiAlias(true);
			if(isChecked()){
				if(null != checkBitmap){
					canvas.drawBitmap(checkBitmap, (getWidth()-checkBitmap.getWidth())/2, (getHeight()-checkBitmap.getHeight())/2, paint);					
				}
			}
			
			if(null != getText()){
				float y = (getHeight() + paint.getTextSize())/2.0f;
				canvas.drawText((String) getText(), (getWidth()-paint.measureText((String) getText()))/2, y, paint);
			}
		}
		
		@Override
		public boolean onTouchEvent(MotionEvent event) {
			switch (event.getAction()) {
			case MotionEvent.ACTION_UP:
				if (dialog.isShowing()) {
					dialog.dismiss();
					// 清除已选中RB状态
					for (CityRadioButton rb : rbs) {
						if (rb.isChecked()) {
							rb.setChecked(false);
							break;
						}
					}
					
					// 设置提交值
					setCityValue(currIC.getValue());
					// 给文本框赋值
					((MyLPCityChooser) realView_).setText(currIC.getName());
//					onClick((String) composited().property_.get("onclick"));
					
					if (saveCity != null && saveCity.length() > 0 && saveCity.equals("true")) {
						PackageManagerAndroid.ANDROIDDB.save(SAVECITY, currIC.getValue());
					}
				}
				break;
			}
			return super.onTouchEvent(event);
		}

		@Override
		public Component composited() {
			// TODO Auto-generated method stub
			return LPCityChooser.this;
		}
	}

	private void initCityDatas(String autoText) {
		Object citysObj = getPropertyByName("citys");
		if (citysObj != null) {
			groupCities = new ArrayList<GroupCity>();
			try {
				JSONArray citysJA = new JSONArray(citysObj.toString());
				for (int i = 0; i < citysJA.length(); i++) {
					GroupCity groupCity = new GroupCity();
					JSONObject citysJO = (JSONObject) citysJA.get(i);

					// 若是"其他"则通过算法找出分类标识(A-G...)
					String groupText = citysJO.getString("group");
					if (groupText != null && (bv_.getString(R.string.others)).equals(groupText)) {
						isShowSearch = false;

						List<ItemCity> itemCitys = new ArrayList<ItemCity>();
						JSONArray cityJA = new JSONArray(citysJO.getString("itemCitys"));
						for (int j = 0; j < cityJA.length(); j++) {
							JSONObject cityJO = (JSONObject) cityJA.get(j);
							String cityName = cityJO.getString("name");
							String cityShort = LPUtils.cn2pinyin(cityName); // 得到城市简拼
							ItemCity itemCity = new ItemCity(cityName, cityJO.getString("value"), cityShort);
							itemCitys.add(itemCity);
						}

						// 开始排序
						if (!itemCitys.isEmpty()) {
							
							// 排序完后, 对列表加入字母
							char prevch = '0';
							GroupCity currGC = null;
							List<ItemCity> currIC = null;
							
							// 交通违章代徽城市简称
							String shortCity = getPropertyByName("shortCity");
							
							if ("true".equals(shortCity)) {
								currIC = new ArrayList<ItemCity>();
								currGC = new GroupCity();
								for (ItemCity itemCity : itemCitys) {
									currIC.add(itemCity);
								}
								currGC.setGroupBy(bv_.getString(R.string.others));
							} else {
								Collections.sort(itemCitys, new Comparator<ItemCity>() {
									@Override
									public int compare(ItemCity o1, ItemCity o2) {
										return o1.getSearchkey().toUpperCase().compareTo(o2.getSearchkey().toUpperCase());
									}
								});
								
//								// 排序完后, 对列表加入字母
//								char prevch = '0';
//								GroupCity currGC = null;
//								List<ItemCity> currIC = null;
								
								for (ItemCity itemCity : itemCitys) {
									char ch = itemCity.getSearchkey().charAt(0);
									
									// A - G
									if ((ch >= 'A' && ch <= 'G') || (ch >= 'a' && ch <= 'g')) {
										if (prevch != 'A') {
											currIC = new ArrayList<ItemCity>();
											currGC = new GroupCity();
											currGC.setGroupBy("A - G");
										}
										prevch = 'A';
										currIC.add(itemCity);
									}
									// H - N
									else if ((ch >= 'H' && ch <= 'N') || (ch >= 'h' && ch <= 'n')) {
										if (prevch != 'H') {
											currGC.setItemCitys(currIC);
											groupCities.add(currGC);
											
											currIC = new ArrayList<ItemCity>();
											currGC = new GroupCity();
											currGC.setGroupBy("H - N");
										}
										prevch = 'H';
										currIC.add(itemCity);
									}
									// P - U
									else if ((ch >= 'P' && ch <= 'U') || (ch >= 'p' && ch <= 'u')) {
										if (prevch != 'P') {
											currGC.setItemCitys(currIC);
											groupCities.add(currGC);
											
											currIC = new ArrayList<ItemCity>();
											currGC = new GroupCity();
											currGC.setGroupBy("P - U");
										}
										prevch = 'P';
										currIC.add(itemCity);
									}
									// W - Z
									else if ((ch >= 'W' && ch <= 'Z') || (ch >= 'w' && ch <= 'z')) {
										if (prevch != 'W') {
											currGC.setItemCitys(currIC);
											groupCities.add(currGC);
											
											currIC = new ArrayList<ItemCity>();
											currGC = new GroupCity();
											currGC.setGroupBy("W - Z");
										}
										prevch = 'W';
										currIC.add(itemCity);
									}
								}
							}
							
							currGC.setItemCitys(currIC);
							groupCities.add(currGC);
						}
					} else {
						groupCity.setGroupBy(groupText);

						List<ItemCity> itemCitys = new ArrayList<ItemCity>();
						JSONArray cityJA = new JSONArray(citysJO.getString("itemCitys"));
						for (int j = 0; j < cityJA.length(); j++) {
							JSONObject cityJO = (JSONObject) cityJA.get(j);
							String searchkey = "";
							if (cityJO.has("searchkey")) {
								searchkey = cityJO.getString("searchkey");
							}

							ItemCity itemCity = null;
							if (autoText != null && autoText.length() > 0) {
								if (searchkey.startsWith(autoText)) {
									itemCity = new ItemCity(cityJO.getString("name"), cityJO.getString("value"), searchkey);
								}
							} else {
								itemCity = new ItemCity(cityJO.getString("name"), cityJO.getString("value"), searchkey);
							}

							// 若不为空 , 则添加
							if (itemCity != null) {
								itemCitys.add(itemCity);
							}
						}
						groupCity.setItemCitys(itemCitys);

						// 若不为空 , 则添加
						if (itemCitys != null && itemCitys.size() > 0) {
							groupCities.add(groupCity);
						}
					}
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	}

	private void addRBView(Context context, LinearLayout rowLL, List<GroupCity> groupCities, LayoutParams lp) {
		int index_ = 0;

		// 添加城市
		if (groupCities != null && groupCities.size() > 0) {
			for (int i = 0; i < groupCities.size(); i++) {
				GroupCity currGC = groupCities.get(i);
				// 分组文本
				String groupText = currGC.getGroupBy();
				TextView gTextView = new TextView(context);
				LinearLayout.LayoutParams gTextViewLP = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
						LayoutParams.WRAP_CONTENT);
				gTextView.setLayoutParams(gTextViewLP);
				gTextView.setPadding(Utils.getScaledValueX(10), 0, 0, 0);
				gTextView.setGravity(Gravity.CENTER_VERTICAL);
				gTextView.setText(groupText);
				//gTextView.setTextSize(Utils.getFontSize(10));
				gTextView.setTextColor(Color.WHITE);
				gTextView.setBackgroundResource(R.drawable.city_title_bg);
				interLL.addView(gTextView);

				// 分组城市
				List<ItemCity> itmeCitys = currGC.getItemCitys();
				if (itmeCitys != null && itmeCitys.size() > 0) {
					for (int j = 0; j < itmeCitys.size(); j++) {
						index_ = j;
						// 实例化RB
						CityRadioButton currRB = new CityRadioButton(context, currGC.getItemCitys().get(j));
						currRB.setLayoutParams(new LinearLayout.LayoutParams(CITY_RB_WIDTH,CITY_RB_HEIGHT));
						
						if (j % col == 0) {
							rowLL = new LinearLayout(context);
							rowLL.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
							rowLL.setOrientation(LinearLayout.HORIZONTAL);
							rowLL.setGravity(Gravity.CENTER_VERTICAL);
							rowLL.addView(currRB);
						} else {
							rowLL.addView(currRB);
							if (j % col == (col - 1)) {
								interLL.addView(rowLL, lp);
							}
						}

						// 存放所有RB城市
						rbs.add(currRB);
					}

					// 处理不足4列场景
					if ((index_ > -1) && ((index_ % col) < (col - 1)) && (rowLL != null)) {
						ViewParent parent_ = rowLL.getParent();
						if (null != parent_) {
							((LinearLayout) parent_).removeView(rowLL);
						}
						interLL.addView(rowLL, lp);
					}
				}
			}
		}
	}
	
	public String air_ = null;
	public void setCityStyle(MyLPCityChooser mlpcc, String cityValue){
		String tag = getPropertyByName("tag");
		if ((tag != null && tag.equals("true")) || (air_ != null && air_.equals("air"))) {
//			if (cityValue.length() >= 4) {
				mlpcc.setPadding(Utils.getScaledValueX(5), 0, Utils.getScaledValueX(5), 0);
//			} else {
//				mlpcc.setPadding(Utils.getScaledValueX(15), 0, Utils.getScaledValueX(15), 0);
//			}
			mlpcc.setTypeface(Typeface.DEFAULT_BOLD);
			mlpcc.setCompoundDrawablesWithIntrinsicBounds(null, null, mlpcc.getResources().getDrawable(R.drawable.tb_3), null);
		}
	}
	
	@Override
	public void releaseResource(Component component) {
		// TODO Auto-generated method stub
		super.releaseResource(component);
		
		Utils.releaseObject(checkBitmap);
		
		if(null != rbs){
			rbs.clear();
			rbs = null;
		}
		
		if(null != groupCities){
			groupCities.clear();
			groupCities = null;
		}
	}
	
	public String getCityName(String value){
		if (rbs != null && rbs.size() > 0) {
			for (int i = 0; i < rbs.size(); i++) {
				CityRadioButton crb = rbs.get(i);
				ItemCity item = crb.currIC;
				if (item != null && item.getValue().equals(value)) {
					return item.getName();
				}
			}
		}
		return null;
	}
}